﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Gift.DAL;
using Gift.Model;
using Gift.Model.ENUM;

namespace WebSite.admin.product
{
    public partial class goodsCompanyList : BaseAdmin
    {
        readonly dalGoodsCompany theGoodsCompany = new dalGoodsCompany();

        protected void Page_Load(object sender, EventArgs e)
        {


            if (!base.IsPostBack)
            {
                base.ValidateLoginRule(ERule.GoodsCompany);
                if (string.IsNullOrEmpty(base.CompanyId))
                {
                    this.btnAddGoods.Visible = false;
                }
                this.DeleletGoodsCompany();
                this.BindGrid();

            }
        }
        private void BindGrid()
        {


            DataTable table = theGoodsCompany.GetList(string.Format(" (goodsName like '%{0}%' or goodsContent like '%{0}%') and isnull(checkStates,0) = {1} and isnull(isDeleted,0)=0  ", this.txtKeywords.Text.Trim(), this.rblProcess.SelectedItem.Value)).Tables[0];
            Grid1.DataSource = table;
            Grid1.DataBind();

            if (string.IsNullOrEmpty(base.CompanyId) && (this.rblProcess.SelectedItem.Value == "0" || this.rblProcess.SelectedItem.Value == "2"))
            {

                this.Grid1.Columns[5].Hidden = false;
              
            }
            else
            {
                this.Grid1.Columns[5].Hidden = true;
            }

        }



        protected void btnSearch_Click(object sender, EventArgs e)
        {
            this.BindGrid();
        }

        protected void Grid1_PageIndexChange(object sender, ExtAspNet.GridPageEventArgs e)
        {
            Grid1.PageIndex = e.NewPageIndex;

        }

        void DeleletGoodsCompany()
        {
            if (Request.QueryString["action"] == "del")
            {
                theGoodsCompany.Delete(int.Parse(Request.QueryString["id"]));
                ExtAspNet.Alert.Show("删除商品信息成功！");
            }
        }

        protected void Grid1_Sort(object sender, ExtAspNet.GridSortEventArgs e)
        {
            DataTable table = theGoodsCompany.GetList("").Tables[0];
            DataView view1 = table.DefaultView;
            view1.Sort = String.Format("{0} {1}", e.SortField, e.SortDirection);
            Grid1.DataSource = view1;
            Grid1.DataBind();
        }



        protected void Window1_Close(object sender, EventArgs e)
        {
            this.BindGrid();
        }




    }
}